package com.net.wanjian.networkhospitalmanager.view;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.utils.DensityToPxUtil;
import com.net.wanjian.networkhospitalmanager.utils.PicassoUtil;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Description:
 * Created by lidongcai on 17/5/3.
 * Email:  lidongcaiocc@163.com
 */

public class QRcodeDialog extends Dialog{
    public QRcodeDialog(@NonNull Context context) {
        super(context);
    }

    public QRcodeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public static class Builder{

        private Context context;
        private String headerImageUrl;
        private String username;
        private String number;
        private Bitmap bitmap;

        public Builder(Context context) {
            this.context = context;
        }

        public String getHeaderImageUrl() {
            return headerImageUrl;
        }

        public Builder setHeaderImageUrl(String headerImageUrl) {
            this.headerImageUrl = headerImageUrl;
            return this;
        }

        public String getUsername() {
            return username;
        }

        public Builder setUsername(String username) {
            this.username = username;
            return this;
        }

        public String getNumber() {
            return number;
        }

        public Builder setNumber(String number) {
            this.number = number;
            return this;
        }

        public Bitmap getBitmap() {
            return bitmap;
        }

        public Builder setBitmap(Bitmap bitmap) {
            this.bitmap = bitmap;
            return this;
        }

        public QRcodeDialog create(){
//            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = LayoutInflater.from(context).inflate(R.layout.dialog_qr_code, null);
//            AutoUtils.auto(view);
            QRcodeDialog dialog = new QRcodeDialog(context, R.style.QRcodeDialog);
            dialog.setContentView(view,new ViewGroup.LayoutParams(DensityToPxUtil.dp2px(context,340),DensityToPxUtil.dp2px(context,450)));

            ImageView headImageView = (ImageView) view.findViewById(R.id.dialog_qrcode_header_iv);
            TextView nameTextView = (TextView) view.findViewById(R.id.dialog_qrcode_name_tv);
            TextView numberTextView = (TextView) view.findViewById(R.id.dialog_qrcode_number_tv);
            ImageView qrImageView = (ImageView) view.findViewById(R.id.dialog_qrcode_iv);

            PicassoUtil.loadImage(context,getHeaderImageUrl(),R.mipmap.infigure_png,headImageView);
            nameTextView.setText(getUsername());
            numberTextView.setText(getNumber());
            qrImageView.setImageBitmap(getBitmap());
            return dialog;
        }
    }
}
